{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 启动VIP服务"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from xtquant import xtdatacenter as xtdc\n",
    "import json\n",
    "\n",
    "with open('config.json', 'r') as file:\n",
    "    # 使用 json.load() 方法将 JSON 数据解析为 Python 字典\n",
    "    data = json.load(file)\n",
    "\n",
    "xtdc.set_token(data['token']) # 这里替换成你的实际token\n",
    "xtdc.init()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 调用VIP接口"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "***** xtdata连接成功 *****\n",
      "服务信息: {'tag': 'xtquant', 'version': '1.0'}\n",
      "服务地址: 127.0.0.1:58609\n",
      "数据路径: d:\\Code\\course\\miniqmt-demo\\data\\datadir\n",
      "设置xtdata.enable_hello = False可隐藏此消息\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>time</th>\n",
       "      <th>bidNumber</th>\n",
       "      <th>bidMostVolume</th>\n",
       "      <th>bidBigVolume</th>\n",
       "      <th>bidMediumVolume</th>\n",
       "      <th>bidSmallVolume</th>\n",
       "      <th>offNumber</th>\n",
       "      <th>offMostVolume</th>\n",
       "      <th>offBigVolume</th>\n",
       "      <th>offMediumVolume</th>\n",
       "      <th>...</th>\n",
       "      <th>unactiveOffMediumVolume</th>\n",
       "      <th>unactiveOffSmallVolume</th>\n",
       "      <th>unactiveBidMostAmount</th>\n",
       "      <th>unactiveBidBigAmount</th>\n",
       "      <th>unactiveBidMediumAmount</th>\n",
       "      <th>unactiveBidSmallAmount</th>\n",
       "      <th>unactiveOffMostAmount</th>\n",
       "      <th>unactiveOffBigAmount</th>\n",
       "      <th>unactiveOffMediumAmount</th>\n",
       "      <th>unactiveOffSmallAmount</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>20230828000000</th>\n",
       "      <td>1693152000000</td>\n",
       "      <td>2126</td>\n",
       "      <td>18024</td>\n",
       "      <td>2711</td>\n",
       "      <td>381</td>\n",
       "      <td>0</td>\n",
       "      <td>2022</td>\n",
       "      <td>17163</td>\n",
       "      <td>2486</td>\n",
       "      <td>287</td>\n",
       "      <td>...</td>\n",
       "      <td>381</td>\n",
       "      <td>0</td>\n",
       "      <td>3.188377e+09</td>\n",
       "      <td>461863321.0</td>\n",
       "      <td>54164577.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.359850e+09</td>\n",
       "      <td>499325941.0</td>\n",
       "      <td>69602718.0</td>\n",
       "      <td>36841.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20230829000000</th>\n",
       "      <td>1693238400000</td>\n",
       "      <td>2313</td>\n",
       "      <td>12067</td>\n",
       "      <td>3346</td>\n",
       "      <td>391</td>\n",
       "      <td>0</td>\n",
       "      <td>1944</td>\n",
       "      <td>9908</td>\n",
       "      <td>2896</td>\n",
       "      <td>342</td>\n",
       "      <td>...</td>\n",
       "      <td>391</td>\n",
       "      <td>0</td>\n",
       "      <td>1.837859e+09</td>\n",
       "      <td>538884826.0</td>\n",
       "      <td>64792822.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.237815e+09</td>\n",
       "      <td>620502667.0</td>\n",
       "      <td>71406441.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20230830000000</th>\n",
       "      <td>1693324800000</td>\n",
       "      <td>1849</td>\n",
       "      <td>6847</td>\n",
       "      <td>2837</td>\n",
       "      <td>465</td>\n",
       "      <td>0</td>\n",
       "      <td>2049</td>\n",
       "      <td>6047</td>\n",
       "      <td>3111</td>\n",
       "      <td>505</td>\n",
       "      <td>...</td>\n",
       "      <td>465</td>\n",
       "      <td>0</td>\n",
       "      <td>1.121008e+09</td>\n",
       "      <td>578142787.0</td>\n",
       "      <td>95420541.0</td>\n",
       "      <td>18456.0</td>\n",
       "      <td>1.269331e+09</td>\n",
       "      <td>524254604.0</td>\n",
       "      <td>84394915.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20230831000000</th>\n",
       "      <td>1693411200000</td>\n",
       "      <td>1702</td>\n",
       "      <td>3566</td>\n",
       "      <td>2393</td>\n",
       "      <td>578</td>\n",
       "      <td>0</td>\n",
       "      <td>1694</td>\n",
       "      <td>5298</td>\n",
       "      <td>2461</td>\n",
       "      <td>524</td>\n",
       "      <td>...</td>\n",
       "      <td>578</td>\n",
       "      <td>0</td>\n",
       "      <td>9.792328e+08</td>\n",
       "      <td>455867915.0</td>\n",
       "      <td>99005437.0</td>\n",
       "      <td>5549.0</td>\n",
       "      <td>6.589979e+08</td>\n",
       "      <td>440736278.0</td>\n",
       "      <td>104599629.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20230901000000</th>\n",
       "      <td>1693497600000</td>\n",
       "      <td>1546</td>\n",
       "      <td>3380</td>\n",
       "      <td>2152</td>\n",
       "      <td>542</td>\n",
       "      <td>0</td>\n",
       "      <td>1642</td>\n",
       "      <td>4263</td>\n",
       "      <td>2303</td>\n",
       "      <td>505</td>\n",
       "      <td>...</td>\n",
       "      <td>542</td>\n",
       "      <td>0</td>\n",
       "      <td>7.908593e+08</td>\n",
       "      <td>427490892.0</td>\n",
       "      <td>94749303.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>6.276429e+08</td>\n",
       "      <td>398660947.0</td>\n",
       "      <td>99219422.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20240328000000</th>\n",
       "      <td>1711555200000</td>\n",
       "      <td>2015</td>\n",
       "      <td>8302</td>\n",
       "      <td>2923</td>\n",
       "      <td>473</td>\n",
       "      <td>0</td>\n",
       "      <td>1934</td>\n",
       "      <td>9723</td>\n",
       "      <td>2835</td>\n",
       "      <td>386</td>\n",
       "      <td>...</td>\n",
       "      <td>473</td>\n",
       "      <td>0</td>\n",
       "      <td>1.656543e+09</td>\n",
       "      <td>485603803.0</td>\n",
       "      <td>67243503.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.416151e+09</td>\n",
       "      <td>496969317.0</td>\n",
       "      <td>79345648.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20240329000000</th>\n",
       "      <td>1711641600000</td>\n",
       "      <td>1701</td>\n",
       "      <td>3208</td>\n",
       "      <td>2528</td>\n",
       "      <td>552</td>\n",
       "      <td>0</td>\n",
       "      <td>1872</td>\n",
       "      <td>3736</td>\n",
       "      <td>2828</td>\n",
       "      <td>604</td>\n",
       "      <td>...</td>\n",
       "      <td>552</td>\n",
       "      <td>0</td>\n",
       "      <td>6.357630e+08</td>\n",
       "      <td>482803333.0</td>\n",
       "      <td>104510024.0</td>\n",
       "      <td>34081.0</td>\n",
       "      <td>5.462333e+08</td>\n",
       "      <td>428993074.0</td>\n",
       "      <td>92244177.0</td>\n",
       "      <td>3400.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20240401000000</th>\n",
       "      <td>1711900800000</td>\n",
       "      <td>2001</td>\n",
       "      <td>11820</td>\n",
       "      <td>2760</td>\n",
       "      <td>408</td>\n",
       "      <td>0</td>\n",
       "      <td>2085</td>\n",
       "      <td>8647</td>\n",
       "      <td>3057</td>\n",
       "      <td>439</td>\n",
       "      <td>...</td>\n",
       "      <td>408</td>\n",
       "      <td>0</td>\n",
       "      <td>1.492340e+09</td>\n",
       "      <td>529183940.0</td>\n",
       "      <td>77277595.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.038137e+09</td>\n",
       "      <td>473789164.0</td>\n",
       "      <td>68642733.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20240402000000</th>\n",
       "      <td>1711987200000</td>\n",
       "      <td>1971</td>\n",
       "      <td>8813</td>\n",
       "      <td>3071</td>\n",
       "      <td>371</td>\n",
       "      <td>0</td>\n",
       "      <td>2301</td>\n",
       "      <td>9123</td>\n",
       "      <td>3604</td>\n",
       "      <td>467</td>\n",
       "      <td>...</td>\n",
       "      <td>371</td>\n",
       "      <td>0</td>\n",
       "      <td>1.563645e+09</td>\n",
       "      <td>618647977.0</td>\n",
       "      <td>81989383.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.510572e+09</td>\n",
       "      <td>524460714.0</td>\n",
       "      <td>61658013.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20240403000000</th>\n",
       "      <td>1712073600000</td>\n",
       "      <td>2040</td>\n",
       "      <td>8697</td>\n",
       "      <td>3035</td>\n",
       "      <td>523</td>\n",
       "      <td>1</td>\n",
       "      <td>2031</td>\n",
       "      <td>13559</td>\n",
       "      <td>2789</td>\n",
       "      <td>442</td>\n",
       "      <td>...</td>\n",
       "      <td>523</td>\n",
       "      <td>1</td>\n",
       "      <td>2.337672e+09</td>\n",
       "      <td>480345156.0</td>\n",
       "      <td>77640417.0</td>\n",
       "      <td>13722.0</td>\n",
       "      <td>1.499227e+09</td>\n",
       "      <td>519517942.0</td>\n",
       "      <td>87912542.0</td>\n",
       "      <td>61741.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>145 rows × 47 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                         time  bidNumber  bidMostVolume  bidBigVolume  \\\n",
       "20230828000000  1693152000000       2126          18024          2711   \n",
       "20230829000000  1693238400000       2313          12067          3346   \n",
       "20230830000000  1693324800000       1849           6847          2837   \n",
       "20230831000000  1693411200000       1702           3566          2393   \n",
       "20230901000000  1693497600000       1546           3380          2152   \n",
       "...                       ...        ...            ...           ...   \n",
       "20240328000000  1711555200000       2015           8302          2923   \n",
       "20240329000000  1711641600000       1701           3208          2528   \n",
       "20240401000000  1711900800000       2001          11820          2760   \n",
       "20240402000000  1711987200000       1971           8813          3071   \n",
       "20240403000000  1712073600000       2040           8697          3035   \n",
       "\n",
       "                bidMediumVolume  bidSmallVolume  offNumber  offMostVolume  \\\n",
       "20230828000000              381               0       2022          17163   \n",
       "20230829000000              391               0       1944           9908   \n",
       "20230830000000              465               0       2049           6047   \n",
       "20230831000000              578               0       1694           5298   \n",
       "20230901000000              542               0       1642           4263   \n",
       "...                         ...             ...        ...            ...   \n",
       "20240328000000              473               0       1934           9723   \n",
       "20240329000000              552               0       1872           3736   \n",
       "20240401000000              408               0       2085           8647   \n",
       "20240402000000              371               0       2301           9123   \n",
       "20240403000000              523               1       2031          13559   \n",
       "\n",
       "                offBigVolume  offMediumVolume  ...  unactiveOffMediumVolume  \\\n",
       "20230828000000          2486              287  ...                      381   \n",
       "20230829000000          2896              342  ...                      391   \n",
       "20230830000000          3111              505  ...                      465   \n",
       "20230831000000          2461              524  ...                      578   \n",
       "20230901000000          2303              505  ...                      542   \n",
       "...                      ...              ...  ...                      ...   \n",
       "20240328000000          2835              386  ...                      473   \n",
       "20240329000000          2828              604  ...                      552   \n",
       "20240401000000          3057              439  ...                      408   \n",
       "20240402000000          3604              467  ...                      371   \n",
       "20240403000000          2789              442  ...                      523   \n",
       "\n",
       "                unactiveOffSmallVolume  unactiveBidMostAmount  \\\n",
       "20230828000000                       0           3.188377e+09   \n",
       "20230829000000                       0           1.837859e+09   \n",
       "20230830000000                       0           1.121008e+09   \n",
       "20230831000000                       0           9.792328e+08   \n",
       "20230901000000                       0           7.908593e+08   \n",
       "...                                ...                    ...   \n",
       "20240328000000                       0           1.656543e+09   \n",
       "20240329000000                       0           6.357630e+08   \n",
       "20240401000000                       0           1.492340e+09   \n",
       "20240402000000                       0           1.563645e+09   \n",
       "20240403000000                       1           2.337672e+09   \n",
       "\n",
       "                unactiveBidBigAmount  unactiveBidMediumAmount  \\\n",
       "20230828000000           461863321.0               54164577.0   \n",
       "20230829000000           538884826.0               64792822.0   \n",
       "20230830000000           578142787.0               95420541.0   \n",
       "20230831000000           455867915.0               99005437.0   \n",
       "20230901000000           427490892.0               94749303.0   \n",
       "...                              ...                      ...   \n",
       "20240328000000           485603803.0               67243503.0   \n",
       "20240329000000           482803333.0              104510024.0   \n",
       "20240401000000           529183940.0               77277595.0   \n",
       "20240402000000           618647977.0               81989383.0   \n",
       "20240403000000           480345156.0               77640417.0   \n",
       "\n",
       "                unactiveBidSmallAmount  unactiveOffMostAmount  \\\n",
       "20230828000000                     0.0           3.359850e+09   \n",
       "20230829000000                     0.0           2.237815e+09   \n",
       "20230830000000                 18456.0           1.269331e+09   \n",
       "20230831000000                  5549.0           6.589979e+08   \n",
       "20230901000000                     0.0           6.276429e+08   \n",
       "...                                ...                    ...   \n",
       "20240328000000                     0.0           1.416151e+09   \n",
       "20240329000000                 34081.0           5.462333e+08   \n",
       "20240401000000                     0.0           2.038137e+09   \n",
       "20240402000000                     0.0           1.510572e+09   \n",
       "20240403000000                 13722.0           1.499227e+09   \n",
       "\n",
       "                unactiveOffBigAmount  unactiveOffMediumAmount  \\\n",
       "20230828000000           499325941.0               69602718.0   \n",
       "20230829000000           620502667.0               71406441.0   \n",
       "20230830000000           524254604.0               84394915.0   \n",
       "20230831000000           440736278.0              104599629.0   \n",
       "20230901000000           398660947.0               99219422.0   \n",
       "...                              ...                      ...   \n",
       "20240328000000           496969317.0               79345648.0   \n",
       "20240329000000           428993074.0               92244177.0   \n",
       "20240401000000           473789164.0               68642733.0   \n",
       "20240402000000           524460714.0               61658013.0   \n",
       "20240403000000           519517942.0               87912542.0   \n",
       "\n",
       "                unactiveOffSmallAmount  \n",
       "20230828000000                 36841.0  \n",
       "20230829000000                     0.0  \n",
       "20230830000000                     0.0  \n",
       "20230831000000                     0.0  \n",
       "20230901000000                     0.0  \n",
       "...                                ...  \n",
       "20240328000000                     0.0  \n",
       "20240329000000                  3400.0  \n",
       "20240401000000                     0.0  \n",
       "20240402000000                     0.0  \n",
       "20240403000000                 61741.0  \n",
       "\n",
       "[145 rows x 47 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from xtquant import xtdata\n",
    "# 获取资金流向\n",
    "xtdata.download_history_data2(stock_list=['600519.SH'], period=\"transactioncount1d\")\n",
    "res = xtdata.get_market_data_ex(stock_list=['600519.SH'],period=\"transactioncount1d\")\n",
    "res['600519.SH']"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "miniqmt-demo-cptEsqYo-py3.10",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
